package com.luo.locationapp.activity;

import com.luo.locationapp.R;
import com.luo.locationapp.utils.PicUtil;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

public class ActivityViewImage extends Activity {
	private ImageView img_src;
	private Intent intent;
	private Bitmap bitmap;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_view_image);
		
		init();
	}
	private void init() {
		img_src = (ImageView) findViewById(R.id.view_image_src);
		intent = getIntent();
		if(intent != null && intent.getStringExtra("path") != null){
			bitmap = PicUtil.getLoacalBitmap(intent.getStringExtra("path"));
			img_src.setImageBitmap(bitmap != null ? bitmap : BitmapFactory.decodeResource(getResources(), R.drawable.default_img));
			ScaleAnimation animation = new ScaleAnimation(0f,1f,0f,1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
			animation.setDuration(300);
			img_src.startAnimation(animation);
		}
		
		img_src.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				if(bitmap != null)
					bitmap.recycle();
				finish();
			}
		});
	}
}
